﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BussinessObject;
using Class_Entity;
using DataAccess;

public partial class Train_Managerment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BlindProductToGridview();

        }
    }
    protected void BlindProductToGridview()
    {
        BO_Train bot = new BO_Train();
        CE__Train cet = new CE__Train();

        GridView1.DataSource = bot.Load_Train(cet);
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        BO_Train bot = new BO_Train();
        CE__Train cet = new CE__Train();

        int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
        cet._TrainID = id;
        bot.Delete_Train(cet);
        BlindProductToGridview();
    }
    /*protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BlindProductToGridview();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        BO_Train bot = new BO_Train();
        CE__Train cet = new CE__Train();

        string idtxt = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
        int id = Convert.ToInt32(idtxt);
        cet._TrainID = id;
        cet._TrainName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
        cet._CategoryID = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text);
        cet._Seat = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text);
        cet._TrainTypeID = Convert.ToInt32(((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text);

        bot.Update_Train(cet);
        GridView1.EditIndex = -1;
        BlindProductToGridview();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BlindProductToGridview();
    }*/
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["ID"] = Convert.ToInt32(GridView1.SelectedRow.Cells[0].Text);
        Response.Redirect("Train-Update.aspx");
    }
}